home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3733 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  61 lines

  1. Path: yellow59.nada.kth.se!md94-pst
  2. From: Per Steneskog <md94-pst@nada.kth.se>
  3. Newsgroups: comp.lang.c
  4. Subject: How to give functions as parameters?
  5. Date: Tue, 30 Jan 1996 22:42:30 +0100
  6. Message-ID: <Pine.SUN.3.91N2x.960130222756.11581A-100000@yellow59.nada.kth.se>
  7. NNTP-Posting-Host: yellow59.nada.kth.se
  8. Mime-Version: 1.0
  9. Content-Type: TEXT/PLAIN; charset=ISO-8859-1
  10. Content-Transfer-Encoding: 8BIT
  11.  
  12.  
  13. I have a little problem, I dont know how to send a fuction,
  14. as a parameter to another function.. 
  15.  
  16.  
  17.  
  18. #include <stdio.h>
  19.  
  20. void
  21. do_it(void (*it)())
  22. {
  23.   ((*(it))());
  24. }
  25.  
  26.    
  27. void
  28. do_me(
  29.       void)
  30. {
  31.   printf("Testing!");
  32. }
  33.  
  34.  
  35. int
  36. main(
  37.      void)
  38. {
  39.   do_it(do_me()); /* ERROR-COMPILE LINE */
  40. }
  41.  
  42.  
  43.  
  44. Short explaination: From main(), do_it() should be called with
  45. the parameter (and function) do_me(). (Pretty obvious :)
  46.  
  47. When I try to compile this, i got the following error message: (gcc)
  48.     In function `main':
  49.     invalid use of void expression
  50.  
  51. My question is, what should I write instead of that line in main()?
  52.  
  53.  
  54. THANKS everyone out there!
  55.  
  56.  
  57.    ///  Per Steneskog     / +46 8 358552 (+1 GMT)              ///
  58.   ///  LinnΘs v. 10 B     / md94-pst@nada.kth.se               ///
  59.  ///  191 47 Sollentuna / http://www.nada.kth.se/~md94-pst/  ///
  60. ///  Sweden            / (last WWW-change 2 years ago :)    ///
  61.